﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

using Microsoft.Scripting;
using Microsoft.Scripting.Ast;
using Microsoft.Linq.Expressions;

namespace DlrBasic.Parser.Ast
{
    static class ArrayHelper
    {
        public static Expression WrapGetArray(Expression getArray)
        {
            Expression nullCheck = Utils.If(ConditionalExpression.Equal(
                getArray, Expression.Null(getArray.Type)),
                Expression.Assign(getArray, Expression.NewArrayBounds(getArray.Type.GetElementType(), Expression.Constant(10)))
                );

            return Expression.Comma(nullCheck, getArray);
        }
    }
}
